package db;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;

import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import javax.swing.JLabel;

import java.awt.Font;

public class Main extends JFrame {

	// 데이터 베이스 연결에 사용할 변수
	static Connection con;

	// 데이터베이스 접속에 정보를 저장한는 변수
	static final String driver = "oracle.jdbc.driver.OracleDriver";
	static final String url = "jdbc:oracle:thin:@192.168.10.4:1521:XE";
	static final String id = "hr";
	static final String password = "hr";

	JDesktopPane contentPane;
	private JPanel panel;
	private JButton btnNewButton;
	private JButton btnNewButton_1;
	private JButton btnNewButton_2;
	JPanel panel_1;
	private JButton button;
	private JLabel label;
	private JButton btnNewButton_3;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Class.forName(driver);
					con = DriverManager.getConnection(url, "hr", "hr");
					System.out.println("오라클 드라이버 로딩 완료");
					Main frame = new Main();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public Main() {
		setTitle("중앙HTA할인매장");
		setBackground(Color.BLACK);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 831, 533);
		contentPane = new JDesktopPane();
		contentPane.setBackground(Color.BLACK);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		contentPane.add(getPanel(), BorderLayout.WEST);
		contentPane.add(getPanel_1(), BorderLayout.CENTER);
//		setResizable(false);

	}

	private JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setBackground(Color.BLACK);
			panel.setPreferredSize(new Dimension(130, 10));
			panel.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 5));
			panel.add(getBtnNewButton_3());
			panel.add(getBtnNewButton_2());
			panel.add(getBtnNewButton());
			panel.add(getButton());
			panel.add(getBtnNewButton_1());
		}
		return panel;
	}

	
		
	
	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("제품 조회");
			btnNewButton.setForeground(Color.WHITE);
			btnNewButton.setBackground(Color.BLACK);
			btnNewButton.setFont(new Font("1훈하얀고양이 R", Font.BOLD, 26));
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					List list = new List(con);
					panel_1.removeAll();
					panel_1.add(list);
					panel_1.updateUI();
					setBounds(100, 100, 831, 533);
					}
			});
			btnNewButton.setPreferredSize(new Dimension(120, 30));
		}
		return btnNewButton;
	}

	private JButton getBtnNewButton_1() {
		if (btnNewButton_1 == null) {
			btnNewButton_1 = new JButton("판매 조회");
			btnNewButton_1.setForeground(Color.WHITE);
			btnNewButton_1.setBackground(Color.BLACK);
			btnNewButton_1.setFont(new Font("1훈하얀고양이 R", Font.BOLD, 26));
			btnNewButton_1.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					SaleList salelist = new SaleList(con, Main.this);
					panel_1.removeAll();
					panel_1.add(salelist);
					panel_1.updateUI();
					setBounds(100, 100, 831, 533);
					}
			});
			btnNewButton_1.setPreferredSize(new Dimension(120, 30));
		}
		return btnNewButton_1;
	}

	private JButton getBtnNewButton_2() {
		if (btnNewButton_2 == null) {
			btnNewButton_2 = new JButton("제품 입력");
			btnNewButton_2.setForeground(Color.WHITE);
			btnNewButton_2.setBackground(Color.BLACK);
			btnNewButton_2.setFont(new Font("1훈하얀고양이 R", Font.BOLD, 26));
			btnNewButton_2.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {	CodeInput input = new CodeInput(con);
				panel_1.removeAll();
				panel_1.add(input);
				panel_1.updateUI();
				setBounds(100, 100, 831, 533);
				
				}
			});
			btnNewButton_2.setPreferredSize(new Dimension(120, 30));
		}
		return btnNewButton_2;
	}

	private JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setPreferredSize(new Dimension(720, 380));
			panel_1.setBackground(Color.BLACK);
			panel_1.setLayout(new BorderLayout(0, 0));
			panel_1.add(getLabel(), BorderLayout.CENTER);
		}
		return panel_1;
	}

	private JButton getButton() {
		if (button == null) {
			button = new JButton("판매");
			button.setForeground(Color.WHITE);
			button.setBackground(Color.BLACK);
			button.setFont(new Font("1훈하얀고양이 R", Font.BOLD, 26));
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					sale sa = new sale(con);
					panel_1.removeAll();
					panel_1.add(sa);
					panel_1.updateUI();
					setBounds(100, 100, 831, 533);
				}
			});
			button.setPreferredSize(new Dimension(120, 30));
		}
		return button;
	}

	private JLabel getLabel() {
		if (label == null) {
			label = new JLabel("");
			label.setIcon(new ImageIcon("C:\\Users\\jhta\\Downloads\\db (2)\\무제-3.jpg"));
		}
		return label;
	}

	private JButton getBtnNewButton_3() {
		if (btnNewButton_3 == null) {
			btnNewButton_3 = new JButton("Main");
			btnNewButton_3.setFont(new Font("1훈하얀고양이 R", Font.BOLD, 26));
			btnNewButton_3.setForeground(Color.WHITE);
			btnNewButton_3.setBackground(Color.BLACK);
			btnNewButton_3.setPreferredSize(new Dimension(120, 30));
			btnNewButton_3.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					panel_1.removeAll();
					panel_1.add(label);
					panel_1.updateUI();
					setBounds(100, 100, 831, 533);
				}
			});
		}
		return btnNewButton_3;
	}
}
